<template>
  <div class="stuEmployContainer">
    <BasicTable @handler="tableHandler" :data="data" :column="column"></BasicTable>
    <editInfoDialog ref="editInfoDialogRef" @reloadData="getData"></editInfoDialog>
  </div>
</template>

<script>
import BasicTable from "@/components/BasicTable/BasicTable"
import { getStuEmploy } from '@/api/user'
import { tableColumn } from '@/constants/stuEmploy'
import editInfoDialog from './components/editInfoDialog/index.vue'

export default {
  name: "index",
  components: {
    BasicTable,
    editInfoDialog
  },
  data() {
    return {
      data: [],
      column: tableColumn
    }
  },
  methods: {
    tableHandler(val) {
      let { type, data } = val
      console.log(type, data)
      switch(type) {
        case 'update':
          this.updateEmploy(data)
          break
        default:
          break
      }
    },
    async getData() {
      const res = await getStuEmploy()
      if (res.success == true) {
        this.data = [res.data]
      } else {
        this.$message.error(res.errorMsg)
      }
    },
    updateEmploy(val) {
      let params = {
        companyName: val.companyName,
        position: val.position,
        signedDate: val.signedDate
      }
      this.$refs.editInfoDialogRef.openDialog(params)
    }
  },
  created() {
    this.getData()
  }
}
</script>

<style scoped lang="sass">
.stuEmployContainer
  padding: 20px
</style>
